/*
 * stateMachine.c
 *
 * Created: 6/29/2013 5:05:16 PM
 *  Author: Tim
 */ 

#include "stateMachine.h"
#include "allocations.h"
#include "../board/board.h"

#include "../packets/structs/msgHeaderDefs.h"
#include "../packets/structs/genPacketStructs.h"
#include "../packets/handlers/adcPacketHandler.h"
#include "../packets/handlers/genPacketHandler.h"



void startProgram()
{	
		
	//turn on timer interrupts if the timers are allocated
	if (daqAlloc.timerAlloc.timerD1Alloc)	TCD1.INTCTRLA = TC_OVFINTLVL_LO_gc;
	PMIC.CTRL |= PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm | PMIC_RREN_bm;

}

void stopProgram()
{	
	//disable com data
	USARTD1.CTRLA &= ~USART_DREINTLVL_gm;
	
	//disable all timer interrupts
	TCD1.INTCTRLA = TC_OVFINTLVL_OFF_gc;

/*	
	//stop all the adc channel interrupts
	ADCA.CH0.INTCTRL = ADC_CH_INTLVL_OFF_gc;
	ADCA.CH1.INTCTRL = ADC_CH_INTLVL_OFF_gc;
	ADCA.CH2.INTCTRL = ADC_CH_INTLVL_OFF_gc;
	ADCA.CH3.INTCTRL = ADC_CH_INTLVL_OFF_gc;
*/	
	//test stuff switch to reset
	//brdInit();
}

void resetDaq()
{
	//test stuff
//	brdInit();
	
//	sendDaqReady();

	CCP = CCP_IOREG_gc;
	RST.CTRL = RST_SWRST_bm;
}
